#Boa:Frame:FrameServicos

import wx
from ControleServico import *
from cadastroServico_Frame import *
import MainFrame
from EditarServ_Frame import *

def create(parent):
    return FrameServicos(parent)

[wxID_FRAMESERVICOS, wxID_FRAMESERVICOSBUTTON1, wxID_FRAMESERVICOSBUTTON3, 
 wxID_FRAMESERVICOSBUTTON4, wxID_FRAMESERVICOSLISTBOX1, 
 wxID_FRAMESERVICOSSTATICBITMAP1, wxID_FRAMESERVICOSSTATICBOX1, 
 wxID_FRAMESERVICOSSTATICTEXT1, 
] = [wx.NewId() for _init_ctrls in range(8)]

class FrameServicos(wx.Frame):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_FRAMESERVICOS, name=u'FrameServicos',
              parent=prnt, pos=wx.Point(461, 88), size=wx.Size(547, 576),
              style=wx.DEFAULT_FRAME_STYLE, title=u'FrameServicos')
        self.SetClientSize(wx.Size(531, 538))
        self.SetBackgroundColour(wx.Colour(255, 255, 255))

        self.staticBox1 = wx.StaticBox(id=wxID_FRAMESERVICOSSTATICBOX1,
              label=u'Servi\xe7os', name='staticBox1', parent=self,
              pos=wx.Point(16, 16), size=wx.Size(496, 296), style=0)
        self.staticBox1.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Tahoma'))

        self.listBox1 = wx.ListBox(choices=[], id=wxID_FRAMESERVICOSLISTBOX1,
              name='listBox1', parent=self, pos=wx.Point(32, 64),
              size=wx.Size(456, 160), style=0)
        self.listBox1.SetBackgroundColour(wx.Colour(251, 251, 251))
        self.listBox1.Bind(wx.EVT_LEFT_DCLICK, self.OnListBox1LeftDclick)

        self.button1 = wx.Button(id=wxID_FRAMESERVICOSBUTTON1,
              label=u'Adicionar Servi\xe7o', name='button1', parent=self,
              pos=wx.Point(40, 240), size=wx.Size(96, 39), style=0)
        self.button1.Bind(wx.EVT_BUTTON, self.OnButton1Button,
              id=wxID_FRAMESERVICOSBUTTON1)

        self.button3 = wx.Button(id=wxID_FRAMESERVICOSBUTTON3,
              label=u'Excluir Servi\xe7o', name='button3', parent=self,
              pos=wx.Point(160, 240), size=wx.Size(96, 40), style=0)
        self.button3.Bind(wx.EVT_BUTTON, self.OnButton3Button,
              id=wxID_FRAMESERVICOSBUTTON3)

        self.button4 = wx.Button(id=wxID_FRAMESERVICOSBUTTON4, label=u'Voltar',
              name='button4', parent=self, pos=wx.Point(392, 248),
              size=wx.Size(96, 40), style=0)
        self.button4.Bind(wx.EVT_BUTTON, self.OnButton4Button,
              id=wxID_FRAMESERVICOSBUTTON4)

        self.staticText1 = wx.StaticText(id=wxID_FRAMESERVICOSSTATICTEXT1,
              label=u'Servi\xe7os Cadastrados', name='staticText1', parent=self,
              pos=wx.Point(32, 40), size=wx.Size(143, 16), style=0)
        self.staticText1.SetFont(wx.Font(10, wx.SWISS, wx.ITALIC, wx.BOLD,
              False, u'Tahoma'))

        self.staticBitmap1 = wx.StaticBitmap(bitmap=wx.Bitmap(u"logotipo300dpi-30%.jpg",
              wx.BITMAP_TYPE_JPEG), id=wxID_FRAMESERVICOSSTATICBITMAP1,
              name='staticBitmap1', parent=self, pos=wx.Point(16, 328),
              size=wx.Size(500, 176), style=0)

    def __init__(self, parent):
        self._init_ctrls(parent)
        
        a = ControleServico()
        a.verificarArquivo()
        for x in a.getListaDeServicos():
            self.listBox1.Append(x.GetNome())

    def OnButton1Button(self, event):
        tela = cadastroServico_Frame(None)
        tela.Show()
        self.Close()

    def OnButton4Button(self, event):
        tela = MainFrame.create(None)
        tela.Show()
        self.Close()

    def OnButton3Button(self, event):
        pos = self.listBox1.GetSelection()
        nome = self.listBox1.GetString(pos)
        obj = ControleServico()
        lista = obj.procurarServicoNome(nome)
        servico = lista[0]

        a = ControleServico()
        a.excluirServico(servico.GetServicoID())
        
        self.listBox1.Delete(pos)
        wx.MessageBox('Servi\xe7o Excluido Com Sucesso', 'Servi\xe7o', wx.OK)

    def OnListBox1LeftDclick(self, event):
        pos = self.listBox1.GetSelection()
        nome = self.listBox1.GetString(pos)
        obj = ControleServico()
        lista = obj.procurarServicoNome(nome)
        servico = lista[0]
        
        tela = EditarServ_Frame(None)
        tela.Show()    
        self.Close()   

        tela.textCtrl1.SetValue(servico.GetServicoID())
        tela.textCtrl2.SetValue(servico.GetNome())
        tela.textCtrl3.SetValue(servico.GetPreco())

